package module;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

public class ProductOrder implements IOrder, Cloneable, Serializable {

	@Override
	public String toString() {
		return "ProductOrder [orderName=" + orderName + ", user=" + user.toString() + "]";
	}

	/**
	 * 
	 */
	private static final long serialVersionUID = -4208517927705834169L;


	private String orderName;
	
	private User   user;
	
	public ProductOrder() {
		this.user = new User();
	}
	
	
	@Override
	public String getOrderName() {
		 
		return orderName;
	}

	@Override
	public void setOrderName(String orderName) {
         this.orderName = orderName;
	}
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}
	
	//浅拷贝
	@Override
	public ProductOrder clone(){
		ProductOrder  order = null;
	    try {  
	    	order = (ProductOrder) super.clone(); 
	    	return order;
        } catch (CloneNotSupportedException e) {  
            System.out.println(e.getMessage());
            return null;
        }  
	}
	
	public Object cloneOrder(){
		 try {  
			  
	            ByteArrayOutputStream ot = new ByteArrayOutputStream();  
	  
	            ObjectOutputStream oo = new ObjectOutputStream(ot);  
	  
	            oo.writeObject(this);  
	  
	            ByteArrayInputStream it = new ByteArrayInputStream(ot.toByteArray());  
	  
	            ObjectInputStream oi = new ObjectInputStream(it);  
	  
	            return (oi.readObject());  
	  
	        } catch (IOException e) {  
	            e.printStackTrace();  
	            return null;  
	        } catch (ClassNotFoundException e) {  
	            e.printStackTrace();  
	            return null;  
	        }  
	}

	

}
